<template>
  <div>
    <div class="tab-list">
      <div class="tab active" v-for="item in data">{{item.label}}</div>
    </div>
    <div class="newstab-list">
      <div class="item active"  v-for="tab in selectList">
        {{tab.label}}
      </div>
      <div class="item active"  v-for="tab in selectList"  v-if="tab.children.length > 0 ">
        <select>
          <option value="sub.id"  v-for="sub in tab.children">{{sub.label}}</option>
        </select>
      </div>
    </div>
  </div>
</template>

<script>
import { getPageData } from "@/api/website";
import { Number } from "core-js";
import $ from 'jquery';
export default {
  props: {
    treeIdChecked: {
      type: Number,
      default: ''
    },
    childIdChecked: {
      type: Number,
      default: ''
    }
  },
  data() {
    return {
      data: [],
      selectList: [],
      defaultExpandedKeys: [3, 8],
      defaultCheckedKeys: [18]
    };
  },
  created() {
    this.init();
    if (this.$route.query.id) {
      this.defaultCheckedKeys = [parseFloat(this.$route.query.id)]
    } else {
      this.defaultCheckedKeys = [parseFloat(this.childIdChecked)]
    }


  },
  mounted() {

  },
  methods: {
    handleNodeClick(data) {
      $(".el-tree-node").removeClass("is-checked")
      if (!data.children || data.children.length == 0) {
        this.$emit('node-click', data.id);
      }
    },
    init() {
      getPageData({ id: this.treeIdChecked }).then(response => {
        let data = response.data.childrenCategory;
        let array = [];
        for (const key in data) {
          array.push({ label: data[key].name, id: data[key].id, children: [] })
          if (data[key].childrenCategory) {
            for (const seckey in data[key].childrenCategory) {
              array[key].children.push({ label: data[key].childrenCategory[seckey].name, id: data[key].childrenCategory[seckey].id, children: [] })
              if (data[key].childrenCategory[seckey].childrenCategory) {
                for (const thrkey in data[key].childrenCategory[seckey].childrenCategory) {
                  array[key].children[seckey].children.push({ label: data[key].childrenCategory[seckey].childrenCategory[thrkey].name, id: data[key].childrenCategory[seckey].childrenCategory[thrkey].id })
                }
              }
            }
          }
        }
        this.data = array;
        this.selectList = this.data[0].children;
        debugger
      });
    }
  }
};
</script>

<style lang="scss"></style>
